package io;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.io.compress.CompressionCodec;
import org.apache.hadoop.io.compress.CompressionOutputStream;
import org.apache.hadoop.util.ReflectionUtils;

public class StreamCompressor {
	public static void main(String[] args) throws  Exception {
		String codecClassname="org.apache.hadoop.io.compress.GzipCodec";//args[0];
		Class<?> codeClass=Class.forName(codecClassname);
		Configuration conf =new Configuration();
		CompressionCodec codec=(CompressionCodec) ReflectionUtils.newInstance(codeClass, conf);
 		InputStream in=new FileInputStream("E:/workspace_personal/hadoop-demo/src/main/java/StreamCompressor.java");
 		OutputStream os=new FileOutputStream(new File("test.zip"));
 		CompressionOutputStream out=codec.createOutputStream(os);

		IOUtils.copyBytes(in, out, 4096,false);
		out.finish();
		in.close();
	}
}
